
export function throttle(fn, delay=100){
    let timer = null
    return function(...args){
        if (timer) return

        timer = setTimeout(function(){
            clearTimeout(timer)
            timer = null
            fn(...args)
        }, delay)
    }
}

export function debounce(fn, delay=100){
    let timer = null
    return function(...args){
        if (timer) return clearTimeout(timer)

        timer = setTimeout(function(){
            clearTimeout(timer)
            timer = null
            fn(...args)
        }, delay)
    }
}

export const  noop = () =>{}

export const isELementNode = el => el && el.nodeType && el.nodeType === 1
export const isTextNode = el => el && el.nodeType && el.nodeType === 3

export const createError = (ctor, msg) => new Error(`[${ctor.name}] ${msg}`)

export const getDom = el => typeof el === 'string' ? document.querySelector(el) : el
